package com.lsyonlygoddes.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

/**
 * @author:lsyonlygoddes
 * @time:2023/11/23 13:03
 */
@CrossOrigin
@RestController
public class UploadController {
    @PostMapping("/upload")
    public void upload(
            @RequestParam("file") MultipartFile file,
            @RequestParam("targetPath") String targetPath
    ) {
        try {
            // 保存文件到服务器 以保存到本机D盘根目录为例
            file.transferTo(new File(targetPath + file.getOriginalFilename()));
            System.out.println("上传成功");
        } catch (Exception e) {
            System.out.println("上传失败");
        }
    }
}
